package com.mc.code.web;

import com.mc.code.entity.Advise;
import com.mc.code.service.AdviseService;
import com.mc.code.service.ItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
@RequestMapping("/mc")
public class IndexController {


    @Autowired
    private ItemsService itemsService;
    @Autowired
    private AdviseService adviseService;

    @RequestMapping("/")
    public String outLogin(Model model) {
        //将已回复的留言的内容在页面上显示（留言的头像、内容、姓名）
        List<Advise> adviseList = adviseService.findAnsweredMessage();
        //随机取一个数
        int count = (int) (Math.random()*(adviseList.size()-2));
        List<Advise> subList = adviseList.subList(count,count+3);
        model.addAttribute("adviseList",subList);
        return "outLoginIndex";
    }

    @RequestMapping("/outLoginIndex")
    public String outLoginIndex(Model model) {
        return "outLoginIndex";
    }

    @RequestMapping("/help")
    public String help(){return "developerHelp";}

    @RequestMapping("/login")
    public String login() {
        return "login";
    }

    @RequestMapping("/register")
    public String register() {
        return "register";
    }

    @RequestMapping("/itemDetails")
    public String itemDetails() {
        return "itemDetails";
    }




}
